"""
智能客服系统配置文件
"""

from typing import Dict, Any, List
from dataclasses import dataclass


@dataclass
class CustomerServiceConfig:
    """客服系统配置类"""
    
    # 基本设置
    system_name: str = "智能客服助手"
    version: str = "1.0.1"
    language: str = "zh-CN"
    
    # 情绪分析设置
    sentiment_threshold: float = 0.6  # 情绪判断阈值
    negative_escalation_threshold: float = 0.7  # 负面情绪自动转接阈值
    
    # 会话设置
    session_timeout_minutes: int = 30  # 会话超时时间（分钟）
    max_message_length: int = 1000  # 最大消息长度
    max_session_messages: int = 100  # 单个会话最大消息数
    
    # 自动回复设置
    enable_auto_reply: bool = True  # 是否启用自动回复
    auto_reply_confidence_threshold: float = 0.8  # 自动回复置信度阈值
    max_auto_reply_suggestions: int = 3  # 最大自动回复建议数
    
    # 人工客服设置
    human_agent_working_hours: Dict[str, str] = None
    estimated_wait_time_minutes: int = 5  # 预估等待时间
    
    # 知识库设置
    knowledge_base_update_interval: int = 24  # 知识库更新间隔（小时）
    
    def __post_init__(self):
        if self.human_agent_working_hours is None:
            self.human_agent_working_hours = {
                "weekdays": "09:00-18:00",
                "weekends": "09:00-18:00"
            }


# 默认配置实例
default_config = CustomerServiceConfig()


# 情绪分析配置
SENTIMENT_CONFIG = {
    "positive_words": [
        "满意", "好", "不错", "棒", "赞", "喜欢", "开心", "高兴", 
        "感谢", "谢谢", "优秀", "完美", "出色", "杰出", "很棒"
    ],
    "negative_words": [
        "不满意", "差", "糟糕", "垃圾", "烂", "讨厌", "愤怒", "生气", 
        "抱怨", "投诉", "失望", "恼火", "不爽", "郁闷", "崩溃"
    ],
    "neutral_words": [
        "一般", "还行", "可以", "普通", "正常", "凑合", "马马虎虎"
    ]
}


# 查询分类配置
QUERY_CATEGORIES = {
    "订单相关": {
        "keywords": ["订单", "发货", "物流", "快递", "配送", "到货", "签收", "查询", "购买", "下单"],
        "priority": "high",
        "auto_reply": True
    },
    "商品相关": {
        "keywords": ["商品", "产品", "质量", "规格", "参数", "功能", "使用", "介绍", "推荐", "搜索"],
        "priority": "medium",
        "auto_reply": True
    },
    "支付相关": {
        "keywords": ["支付", "付款", "价格", "费用", "优惠", "折扣", "促销", "退款", "优惠券"],
        "priority": "high",
        "auto_reply": True
    },
    "购物车相关": {
        "keywords": ["购物车", "加入", "删除", "清空", "结算", "数量", "修改", "商品管理"],
        "priority": "medium",
        "auto_reply": True
    },
    "积分系统": {
        "keywords": ["积分", "签到", "登录奖励", "兑换", "会员", "特权", "等级", "消费积分"],
        "priority": "medium",
        "auto_reply": True
    },
    "售后相关": {
        "keywords": ["退货", "换货", "维修", "保修", "售后", "质量问题", "故障", "投诉"],
        "priority": "high",
        "auto_reply": False
    },
    "账户相关": {
        "keywords": ["账户", "登录", "密码", "注册", "会员", "个人信息", "设置", "安全"],
        "priority": "medium",
        "auto_reply": True
    },
    "智能推荐": {
        "keywords": ["推荐", "个性化", "偏好", "兴趣", "相似", "猜你喜欢", "为你推荐"],
        "priority": "low",
        "auto_reply": True
    },
    "客服助手": {
        "keywords": ["AI", "智能", "机器人", "自动", "客服", "助手", "人工", "转接"],
        "priority": "low",
        "auto_reply": True
    },
    "投诉建议": {
        "keywords": ["投诉", "建议", "意见", "反馈", "举报", "不满", "问题", "改进"],
        "priority": "urgent",
        "auto_reply": False
    },
    "其他问题": {
        "keywords": ["客服", "咨询", "帮助", "联系方式", "其他", "不知道", "随便问问"],
        "priority": "low",
        "auto_reply": True
    }
}


# 常见问题配置
FAQ_DATABASE = {
    "退货相关": {
        "如何退货": {
            "answer": "退货流程：1.登录账户->我的订单->申请退货 2.填写退货原因 3.打包商品并贴上退货单 4.联系快递上门取件 5.退款将在收到商品后3-5个工作日内处理完成。",
            "confidence": 0.9
        },
        "退货条件": {
            "answer": "我们支持7天无理由退货，商品需保持原包装完好，未使用状态。特殊商品（如内衣、食品等）不支持无理由退货。",
            "confidence": 0.9
        },
        "退款时间": {
            "answer": "退款处理时间：收到退货商品后3-5个工作日内处理退款，退款将原路返回到您的支付账户。",
            "confidence": 0.9
        }
    },
    "配送相关": {
        "配送时间": {
            "answer": "配送时间说明：工作日下单当天发货，周末下单周一发货。一般3-5个工作日送达，偏远地区可能需要7-10个工作日。",
            "confidence": 0.9
        },
        "配送费用": {
            "answer": "配送费用：订单满99元免费配送，不满99元收取10元配送费。会员享受免费配送服务。",
            "confidence": 0.9
        },
        "配送范围": {
            "answer": "我们支持全国配送，包括偏远地区。港澳台地区需要额外配送费用，具体请咨询客服。",
            "confidence": 0.9
        }
    },
    "支付相关": {
        "支付方式": {
            "answer": "我们支持微信支付、支付宝、银行卡、信用卡等多种支付方式。所有支付都经过加密处理，安全可靠。",
            "confidence": 0.9
        },
        "支付安全": {
            "answer": "支付安全保障：我们采用SSL加密技术，支持多种安全支付方式，所有交易信息都经过加密处理，请放心支付。",
            "confidence": 0.9
        }
    },
    "会员相关": {
        "会员权益": {
            "answer": "会员专享权益：1.专属折扣优惠 2.生日礼品 3.积分加倍奖励 4.优先客服服务 5.新品抢先体验 6.免费配送服务 7.专属客服热线 8.会员月卡特权。",
            "confidence": 0.9
        },
        "积分规则": {
            "answer": "积分获取规则：\n1.每日登录：5积分\n2.购物消费：每消费1元获得1积分\n3.完善资料：20积分（一次性）\n4.商品评价：每个商品10积分\n5.分享商品：每天最多3次，每次15积分\n\n积分有效期：永久有效，不会过期清零。",
            "confidence": 0.95
        },
        "积分兑换": {
            "answer": "积分兑换选项：\n1.5元优惠券（100积分）- 满50元可用\n2.10元优惠券（200积分）- 满100元可用\n3.20元优惠券（400积分）- 满200元可用\n4.免运费券（150积分）- 任意订单可用\n5.会员月卡（500积分）- 1个月会员特权\n\n兑换后的优惠券和特权将自动添加到您的账户中。",
            "confidence": 0.95
        },
        "积分查询": {
            "answer": "积分查询方式：\n1.登录平台首页即可查看当前积分余额\n2.在'我的积分'页面查看详细积分明细和兑换记录\n3.每次积分变动都会有系统通知\n\n如需查询历史积分记录，请在个人中心-积分管理中查看。",
            "confidence": 0.9
        }
    },
    "积分系统": {
        "积分获取方式": {
            "answer": "获取积分的5种方式：\n\n📅 每日登录：每天首次登录获得5积分\n💰 购物消费：每消费1元获得1积分，无上限\n📝 完善资料：完善个人资料一次性获得20积分\n⭐ 商品评价：为购买的商品写评价，每个商品10积分\n📱 分享商品：分享商品到社交平台，每天最多3次，每次15积分\n\n小贴士：购物时积分会自动计算，评价和分享需要手动操作哦！",
            "confidence": 0.95
        },
        "积分兑换流程": {
            "answer": "积分兑换流程：\n\n1️⃣ 进入'我的积分'页面\n2️⃣ 查看可兑换的奖励列表\n3️⃣ 选择想要兑换的奖励\n4️⃣ 确认积分余额是否足够\n5️⃣ 点击兑换按钮完成兑换\n6️⃣ 兑换成功后奖励自动添加到账户\n\n注意：兑换的优惠券会在'我的优惠券'中显示，会员特权立即生效。",
            "confidence": 0.9
        },
        "积分使用限制": {
            "answer": "积分使用说明：\n\n✅ 积分永久有效，不会过期\n✅ 每日登录奖励每天只能获得一次\n✅ 商品评价每个商品只能获得一次积分\n✅ 分享奖励每天最多获得3次\n✅ 完善资料奖励只能获得一次\n\n❌ 积分不能转让给其他用户\n❌ 积分不能直接抵扣现金\n❌ 某些活动积分可能有特殊使用规则",
            "confidence": 0.9
        },
        "积分常见问题": {
            "answer": "积分常见问题解答：\n\nQ: 为什么我的积分没有增加？\nA: 请检查是否符合积分获取条件，如每日登录只能获得一次，商品评价需要实际购买后才能获得积分。\n\nQ: 兑换的优惠券在哪里查看？\nA: 在'我的优惠券'页面可以查看所有可用的优惠券和使用期限。\n\nQ: 积分会过期吗？\nA: 我们的积分永久有效，不会过期清零，请放心积累使用。",
            "confidence": 0.9
        }
    },
    "发票相关": {
        "发票开具": {
            "answer": "发票开具说明：支持开具电子发票和纸质发票，请在下单时选择发票类型并填写发票信息。电子发票将在付款后24小时内发送到您的邮箱。",
            "confidence": 0.9
        }
    },
    "购物车相关": {
        "商品添加": {
            "answer": "添加商品到购物车：\n1.浏览商品页面，选择规格和数量\n2.点击'加入购物车'按钮\n3.在购物车中可以修改数量或删除商品\n4.支持批量操作和收藏功能\n\n购物车商品会保存7天，过期后自动清理。",
            "confidence": 0.9
        },
        "购物车管理": {
            "answer": "购物车功能说明：\n📦 查看已添加的商品和总价\n🔢 修改商品数量（库存充足时）\n🗑️ 移除不需要的商品\n🛒 一键清空购物车\n💰 实时计算优惠和运费\n\n提示：购物车商品库存实时更新，建议及时下单。",
            "confidence": 0.9
        },
        "结算流程": {
            "answer": "购物车结算步骤：\n1️⃣ 确认购物车商品和数量\n2️⃣ 选择收货地址\n3️⃣ 选择配送方式\n4️⃣ 选择支付方式\n5️⃣ 使用优惠券（如有）\n6️⃣ 确认订单信息\n7️⃣ 完成支付\n\n支付成功后会收到订单确认短信和邮件。",
            "confidence": 0.9
        }
    },
    "智能推荐": {
        "推荐原理": {
            "answer": "智能推荐系统说明：\n🔍 基于您的浏览历史和购买记录\n👥 参考相似用户的购买偏好\n🏷️ 商品标签和分类匹配\n⭐ 考虑商品评价和热度\n🎯 个人偏好学习和优化\n\n系统会不断学习您的喜好，推荐越来越精准。",
            "confidence": 0.9
        },
        "推荐设置": {
            "answer": "个性化推荐设置：\n✅ 可以在个人设置中开启/关闭推荐\n✅ 支持设置兴趣标签和偏好\n✅ 可以屏蔽特定类别的商品\n✅ 支持反馈推荐质量（喜欢/不喜欢）\n\n您的反馈会帮助我们提供更好的推荐。",
            "confidence": 0.9
        }
    },
    "客服助手": {
        "AI助手功能": {
            "answer": "智能客服助手能力：\n🤖 24小时在线，即时响应\n📚 丰富的商品和服务知识库\n🔍 快速查询订单和物流信息\n💡 智能推荐相关商品\n📝 记录完整的咨询历史\n\n复杂问题会转接人工客服，确保问题得到解决。",
            "confidence": 0.9
        },
        "使用技巧": {
            "answer": "AI客服使用技巧：\n💬 直接描述问题，无需客套话\n🔢 提供订单号可快速查询\n📷 支持发送图片描述问题\n❓ 不确定时可以说'不知道'或'其他'\n🔄 不满意回答可以要求重新解答\n\n说'转人工'可直接转接人工客服。",
            "confidence": 0.9
        }
    }
}


# 产品推荐配置
PRODUCT_RECOMMENDATIONS = {
    "手机": [
        {"name": "华为P60 Pro", "price": "5999", "rating": "4.8", "features": ["高清摄像", "快速充电", "大容量电池"]},
        {"name": "小米13 Ultra", "price": "4999", "rating": "4.7", "features": ["徕卡摄像", "骁龙8Gen2", "无线充电"]},
        {"name": "OPPO Find X6", "price": "4499", "rating": "4.6", "features": ["超级快充", "影像旗舰", "轻薄设计"]},
        {"name": "vivo X90", "price": "3999", "rating": "4.5", "features": ["蔡司光学", "天玑9200", "大电池"]}
    ],
    "电脑": [
        {"name": "联想ThinkPad X1", "price": "8999", "rating": "4.9", "features": ["商务办公", "长续航", "轻薄便携"]},
        {"name": "戴尔XPS13", "price": "7999", "rating": "4.8", "features": ["窄边框", "高性能", "设计精美"]},
        {"name": "华为MateBook X", "price": "6999", "rating": "4.7", "features": ["触控屏", "快速充电", "金属机身"]},
        {"name": "苹果MacBook Air", "price": "9999", "rating": "4.8", "features": ["M2芯片", "超长续航", "静音设计"]}
    ],
    "耳机": [
        {"name": "AirPods Pro 2", "price": "1899", "rating": "4.8", "features": ["主动降噪", "透明模式", "空间音频"]},
        {"name": "索尼WH-1000XM5", "price": "2399", "rating": "4.9", "features": ["顶级降噪", "LDAC音质", "30h续航"]},
        {"name": "Bose QC45", "price": "2199", "rating": "4.7", "features": ["舒适佩戴", "清晰通话", "快速充电"]},
        {"name": "森海塞尔HD660S", "price": "3299", "rating": "4.8", "features": ["HiFi音质", "开放式", "专业监听"]}
    ],
    "智能手表": [
        {"name": "Apple Watch Series 9", "price": "2999", "rating": "4.8", "features": ["健康监测", "运动追踪", "生态完整"]},
        {"name": "华为Watch GT 4", "price": "1488", "rating": "4.6", "features": ["长续航", "健康管理", "时尚设计"]},
        {"name": "小米Watch S1", "price": "1099", "rating": "4.5", "features": ["蓝宝石屏", "独立通话", "运动模式"]}
    ]
}


# 联系方式配置
CONTACT_INFO = {
    "customer_service": {
        "name": "客户服务",
        "phone": "400-123-4567",
        "email": "service@company.com",
        "wechat": "Company_Service",
        "qq": "123456789",
        "working_hours": "周一至周日 9:00-18:00",
        "description": "产品咨询、订单查询、售前售后服务"
    },
    "technical_support": {
        "name": "技术支持",
        "phone": "400-123-4568",
        "email": "tech@company.com",
        "working_hours": "周一至周五 9:00-18:00",
        "description": "产品技术问题、使用指导、故障排除"
    },
    "complaints": {
        "name": "投诉建议",
        "phone": "400-123-4569",
        "email": "complaint@company.com",
        "working_hours": "周一至周日 9:00-18:00",
        "description": "服务投诉、意见建议、质量问题反馈"
    },
    "vip_service": {
        "name": "VIP专线",
        "phone": "400-123-4570",
        "email": "vip@company.com",
        "working_hours": "周一至周日 24小时",
        "description": "VIP会员专属服务，优先处理"
    }
}


# 自动回复模板配置
AUTO_REPLY_TEMPLATES = {
    "greeting": [
        "您好！欢迎咨询，我是智能客服助手，很高兴为您服务！",
        "您好！我是您的专属客服，有什么可以帮助您的吗？",
        "欢迎来到客服中心，请问有什么需要帮助的？"
    ],
    "positive_sentiment": [
        "很高兴听到您的满意反馈！",
        "谢谢您的好评，我们会继续努力！",
        "您的支持是我们前进的动力！",
        "感谢您的认可，我们会保持优质服务！"
    ],
    "negative_sentiment": [
        "非常抱歉给您带来不便，我会立即为您处理这个问题。",
        "我理解您的困扰，让我来帮您解决这个问题。",
        "感谢您的反馈，我们会认真对待并改进。",
        "很抱歉让您有不好的体验，我会尽力帮您解决。"
    ],
    "order_inquiry": [
        "请提供您的订单号，我来帮您查询订单状态。",
        "我来为您查询订单信息，请稍等。",
        "好的，我马上为您查询订单详情。"
    ],
    "product_inquiry": [
        "我来为您详细介绍一下这个商品的信息。",
        "关于这个产品，我来为您详细说明。",
        "让我为您介绍一下产品的详细参数。"
    ],
    "cart_inquiry": [
        "我来帮您查看购物车信息和处理相关问题。",
        "关于购物车操作，我来为您详细说明。",
        "让我帮您管理购物车中的商品。"
    ],
    "points_inquiry": [
        "我来为您查看积分余额和使用说明。",
        "关于积分系统，我来为您详细介绍。",
        "让我帮您了解积分获取和兑换方式。"
    ],
    "recommendation_inquiry": [
        "我来为您推荐合适的商品。",
        "基于您的喜好，我来为您个性化推荐。",
        "让我为您找到可能感兴趣的商品。"
    ],
    "after_sales": [
        "我来为您处理售后问题，请详细描述遇到的情况。",
        "关于售后服务，我会为您详细说明处理流程。",
        "我会为您安排售后服务，请提供详细信息。"
    ],
    "escalation": [
        "为了更好地解决您的问题，我为您转接人工客服。",
        "这个问题需要专业客服处理，正在为您转接。",
        "我为您安排专门的客服代表来处理这个问题。"
    ],
    "closing": [
        "感谢您的咨询，祝您生活愉快！",
        "很高兴为您服务，如有其他问题请随时联系！",
        "问题已经解决，感谢您的耐心，再见！"
    ]
}


# 满意度评价配置
SATISFACTION_CONFIG = {
    "rating_scale": {
        1: {"level": "非常不满意", "color": "red", "action": "escalate"},
        2: {"level": "不满意", "color": "orange", "action": "follow_up"},
        3: {"level": "一般", "color": "yellow", "action": "improve"},
        4: {"level": "满意", "color": "lightgreen", "action": "maintain"},
        5: {"level": "非常满意", "color": "green", "action": "appreciate"}
    },
    "feedback_categories": [
        "服务态度", "响应速度", "问题解决", "专业程度", "整体体验"
    ]
}


# 质量控制配置
QUALITY_CONTROL = {
    "response_time_targets": {
        "auto_reply": 1,  # 秒
        "human_agent": 60,  # 秒
        "complex_issue": 300  # 秒
    },
    "escalation_triggers": [
        "customer_waiting_too_long",
        "negative_sentiment_high",
        "complex_technical_issue",
        "repeated_same_issue",
        "customer_request_human"
    ],
    "monitoring_metrics": [
        "response_time",
        "resolution_rate", 
        "customer_satisfaction",
        "first_contact_resolution",
        "escalation_rate"
    ]
}
